<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 3.对数组排序，从小到大
    //选择排序
    function SelectSort(array) {
        let minIndex;
        for (let i = 0; i < array.length - 1; i++) {
            minIndex = i;
            for (let j = i + 1; j < array.length; j++) {
                minIndex = array[minIndex] < array[j] ? minIndex : j;
            }
            let temp;
            temp = array[i];
            array[i] = array[minIndex];
            array[minIndex] = temp;
        }
        return array;
    }
    arr = [19, 32, 4, 7, 67, 43];
    console.log(SelectSort(arr))
    // 6.和电脑猜拳10次(电脑出拳用随机数)，显示每次结果，最后累计输赢平局结果
    function getRandomIntInclusive(min, max) {
        min = Math.ceil(min);
        max = Math.floor(max);
        return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值，含最小值
    }

    function win(num1, num2) {
        if (num1 == 0 && num2 == 2 || num1 == 1 && num2 == 0 || num1 == 2 && num2 == 1) {
            return num1;
        } else {
            return num2;
        }
    }
    let game = [];
    let times = 0;
    console.log('猜拳游戏（0表示石头，1表示布，2表示剪刀）');
    for (let i = 0; i < 3; i++) {
        let num = getRandomIntInclusive(0, 2);
        game[i] = prompt("猜拳，请输入（0表示石头，1表示布，2表示剪刀）：");
        console.log('电脑：' + num + '\t玩家:' + game[i]);
        if (win(num, game[i]) == num) {
            times++;
        }
    }
    if (times > 3 - times) {
        console.log('电脑获胜！');
    } else if (times = 3 - times) {
        console.log('恭喜你获胜了！');
    } else {
        console.log('平局!');
    }
</script>

</html>